package com.cst311zrb.recyclerviewdata311zrb.Activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;

import com.cst311zrb.recyclerviewdata311zrb.Adapter.MyAdapter;
import com.cst311zrb.recyclerviewdata311zrb.Iface.ArticleListener;
import com.cst311zrb.recyclerviewdata311zrb.Model.ArticleModel;
import com.cst311zrb.recyclerviewdata311zrb.R;
import com.cst311zrb.recyclerviewdata311zrb.bean.ArticleBean;

import java.util.List;

public class MainActivity extends AppCompatActivity implements ArticleListener {
    private List<ArticleBean> list;
    private RecyclerView recyclerView;
    private RecyclerView.LayoutManager layoutManager;
    private MyAdapter mAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initRecyclerView();
        ArticleModel articleModel=new ArticleModel();
        articleModel.getResultList("article",2,"2ts2j910hv4m270hipde4a67d7",this);
    }


    private void initRecyclerView() {
        recyclerView=(RecyclerView)findViewById(R.id.recyclerview);
        layoutManager=new LinearLayoutManager(this);
        recyclerView.setLayoutManager(layoutManager);
        /*list=getData();*/
        mAdapter=new MyAdapter(this);
        mAdapter.setList(list);
        recyclerView.setAdapter(mAdapter);
    }



    @Override
    public void onResponse(List<ArticleBean> list) {
        this.list=list;
        mAdapter.setList(list);
        mAdapter.notifyDataSetChanged();
    }

    @Override
    public void onFail(String msg) {
        Toast.makeText(this,"fail:"+msg, Toast.LENGTH_SHORT);

    }
}
